package com.dp.singleton;

/**
 * @Author: Ruomeng
 * @Date: 2024/11/5
 * @Description : 单例模式-静态内部类 （懒加载）
 * @Version: 1.0
 */
public class InnerClassSingleton {

    private InnerClassSingleton() {
        if (SingletonHandler.instance != null) {
            throw new RuntimeException("不允许非法访问");
        }
    }

    //创建静态内部类
    private static class SingletonHandler {
        private static InnerClassSingleton instance = new InnerClassSingleton();
    }

    public static InnerClassSingleton getInstance() {
        return SingletonHandler.instance;
    }

}
